package xiancheng.runnable;

/**
 * 
 * @author Jin Jing
 * 
 * 通过实现Runnable接口,然后创建线程对象并启动，实际上和直接继承Thread类是一个意思
 *
 */
public class RunPingPong implements Runnable{
	private String word;
	
	private int delay;
	
	public RunPingPong(String whatToSay, int delayTime) {
		word = whatToSay;
		delay = delayTime;
	}
	
	public void run() {
		try {
			for(;;) {
				System.out.println(word + " ");
				Thread.sleep(delay);
			}
		} catch (Exception e) {
			return;
		}
	}
	
	public static void main(String[] args) {
		Runnable ping = new RunPingPong("ping", 33);
		Runnable pong = new RunPingPong("pong", 100);
		new Thread(ping).start();
		new Thread(pong).start();

	}

}
